<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\configs\admin;

use app\admin\controller\Admin;
use think\Db;
use app\common\builder\ZBuilder;

/**
 * dept控制器
 * @package app\banner\admin
 */
class Order extends Admin
{
    /**
     * 首页
     * @author 蔡伟明 <314013107@qq.com>
     * @return mixed
     */
    public function index(){
        $map = $this->getMap();
        
        $data_list = db::name('order')
            ->alias("a")
            ->where($map)
            ->where(["a.status"=>1])
            ->join("user b","a.user_id=b.id","left")
            ->join("user c","a.re_id=c.id","left")
            ->join("card d","a.card_id=d.id","left")
            ->field("a.*,b.username,b.nickname,b.mobile,c.username re_username,c.nickname re_nickname,c.mobile re_mobile,d.card_code")
            ->order("a.id desc")
            ->paginate();

        // 使用ZBuilder快速创建数据表格
        return ZBuilder::make('table')
            ->setPageTitle('订单管理') // 设置页面标题
            ->setTableName('order') // 设置数据表名
            ->hideCheckbox()
            ->setSearch(['a.out_trade_no' => '订单号','c.username' => '商家姓名']) // 设置搜索参数
            ->addColumns([ // 批量添加列
                ['id','ID'],
                ['out_trade_no','订单号'],
                ['total_fee','实付金额'],
                ['all_fee','应付金额'],
                ['save_fee','折扣金额'],
                ['username','客户姓名'],
                ['re_username','商家姓名'],
                ['card_code','卡号'],
                ['create_time','下单时间'],
                ['pay_time','付款时间'],
                ['right_button', '操作', 'btn']
            ])
            ->addRightButtons('delete') // 批量添加右侧按钮
            ->setRowList($data_list) // 设置表格数据
            ->setColumnWidth(["title"=>150])
            ->fetch(); // 渲染页面
    }
}
